package servlet;

import domain.Product;
import service.ProductService;
import service.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.beans.Beans;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created by guo on 2017/10/24.
 */
@WebServlet(name = "AddServlet",urlPatterns = "/addServlet")
public class AddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
         String pname=request.getParameter("name");
         Double market_price=Double.valueOf(request.getParameter("mprice"));
         Double shop_price=Double.valueOf(request.getParameter("sprice"));
         String pdesc=request.getParameter("desc");

        try {
            ProductService productService=new ProductServiceImpl();
           Boolean ps = productService.Add(pname,market_price,shop_price,pdesc);
            response.sendRedirect("/untitled/showListServlet");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
